<template>
  <div>
    <div class="heade">
      <img :src="'http://liufusong.top:8080'+user.avatar" alt="" />
      <div class="box">
        <img src="	http://liufusong.top:8080/img/profile/avatar.png" alt="" />
        <p>{{user.nickname}}</p>
        <button @click="loginUser" v-if='show'>去登录</button>
        <!-- <button @click="backUser" v-else>退出登录</button> -->
        <van-button type="primary"  @click="backUser" v-if='!show' class='backuser'>退出</van-button>
        <div class='info'>编辑个人资料 <van-icon name="play" /></div>
      </div>
    </div>
    <div class='center'>
      <van-grid clickable :column-num="3" :border='false' class='box-item'>
   <van-grid-item icon="star-o" text="我的收藏" to="/mycollect" />
   <van-grid-item icon="wap-home-o" text="我的出租" to="/" />
   <van-grid-item icon="clock-o" text="看房记录" to="/" />
   <van-grid-item icon="idcard" text="成为房主" to="/" />
   <van-grid-item icon="contact" text="个人资料" to="/" />
   <van-grid-item icon="service-o" text="联系我们" url="/vant/mobile.html" />
 </van-grid>
    </div>
    <div class='footImg'>
      <img src="http://liufusong.top:8080/img/profile/join.png" alt="">
    </div>
  </div>
</template>

<script>
import { getToken } from "@/utils/storage";
import {delToken} from '@/utils/storage'
import {userInformation} from '@/api/users'
export default {
  name: "UserPage",
  components: {},
  props: {},
  data() {
    return {
      user:{
  avatar: "/img/profile/bg.png",
  gender: "",
  nickname: "游客",
  phone: "",
},
show:true,
    };
  },
  computed: {},
  watch: {},
   async created() {
   const {body}= await userInformation(this.user)
    // console.log(body);
    if(getToken()){
      this.user.avatar=body.avatar
      this.user.nickname=body.nickname
      this.show=!this.show
    }
    
  },
  methods: {
    loginUser(){
     this.$router.push('/login')
    },
    backUser(){
      delToken()

      this.$router.push('/login')
    }
  },
};
</script>

<style scoped lang="less">
.heade {
  position: relative;
  width: 100%;
  height: 300px;
  // background-color: pink;
  img {
    width: 100%;
  }
  .box {
    z-index:1;
    position: absolute;
    background: #fff;
    width: 80%;
    height: 60%;
    bottom: -50px;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 0 10px 3px #ddd;
    margin: 10px auto 0;
    padding: 0 20px;
    text-align: center;
    font-size: 13px;
    .info{
      color: #999;
      font-size: 12px;
      
    }
    img {
      position: absolute;
      top: -35px;
      left: 135px;
      width: 70px;
      height: 70px;
    }
    p {
      margin-top: 50px;
      font-size: 13px;
      height: 10px;
    }
    button {
      margin-top: 10px;
      border-radius: 5px;
      height: 30px;
      font-size: 13px;
      line-height: 30px;
      padding: 0 15px;
      background-color: #21b97a;
      border-style: none;
      color: #fff;
    }
    .backuser{
      border-radius: 30px;
      height: 20px;
      margin-top: -30px;
      margin-bottom: 30px;
    }
  }
}
.center{
  margin-top: 50px;
}
.footImg{
  margin-top: 20px;
  width: 100%;
   height: 115px;
   img{
    width: 92%;
   }
}
</style>
